package com.qm.web.controller;

import com.qm.domain.bean.AgencyResource;
import com.qm.web.converter.JsonArg;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by wodvpn on 2017/1/14.
 */
@RestController
public class AgencyController {


	@RequestMapping("/agencies")
	public List<AgencyResource> getAgencies() {
		List<AgencyResource> agencies = getListing();
		return agencies;
	}

	@RequestMapping(value = "/add",method = RequestMethod.POST,produces ="application/json")
	public AgencyResource addAgency(@RequestBody AgencyResource ar) {
		System.out.println(ar);;
		return ar;
	}

	@RequestMapping(value = "/addTwo",method = RequestMethod.POST,produces ="application/json")
	public List<AgencyResource> addAgency2(@JsonArg("$.agent1") AgencyResource ar1,@JsonArg("$.agent2") AgencyResource ar2) {
		List<AgencyResource> lst = new ArrayList<>();
		lst.add(ar1);
		lst.add(ar2);
		System.out.println(ar1);;
		System.out.println(ar2);;
		return lst;
	}

	@RequestMapping(value = "/addTwoList",method = RequestMethod.POST,produces ="application/json")
	public List<List<AgencyResource>> addAgency3(@JsonArg("$.agent1") List<AgencyResource> ar1,@JsonArg("$.agent2") List<AgencyResource>  ar2) {
		List<List<AgencyResource>> lst = new ArrayList<>();
		lst.add(ar1);
		lst.add(ar2);
		System.out.println(ar1);;
		System.out.println(ar2);;
		return lst;
	}

	private List<AgencyResource> getListing() {

		List<AgencyResource> resources = new ArrayList<>();
		resources.add(new AgencyResource(1, "All State", "123"));
		resources.add(new AgencyResource(2, "FCCI Insurance Group", "456"));
		resources.add(new AgencyResource(3, "Farmers", "789"));
		resources.add(new AgencyResource(4, "Met life", "167"));
		return resources;
	}
	//..
}
